package com.alienlab.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.googlecode.asyn4j.core.callback.AsynCallBack;

import static com.alienlab.utils.Pdf2htmlEXUtil.pdf2html;

//异步执行类
public class NewsProcess {
	
	//异步执行类，获取所有的下载地址
	public NewsBeanData getResult(NewsBeanData newsBeanData){
		JSONArray jsonArray = new JSONArray();
		NewsJsoup newsJsoup = new NewsJsoup();
		List<String> name = new ArrayList<>();
		name.add(newsBeanData.getName());
		List<String> url = new ArrayList<>();
		url.add(newsBeanData.getUrl());
		jsonArray = newsJsoup.getUrlPdf(name, url,newsBeanData.getPath());
		System.out.println("报纸url");
		newsBeanData.setJsonArray(jsonArray);
		if(jsonArray.size()>0){
			JSONArray jsonArrayPdf = jsonArray.getJSONArray(0);
			if(jsonArrayPdf.size()>0){
				for (int i=0;i<jsonArrayPdf.size();i++){
                    String pdfInfo = jsonArrayPdf.get(i).toString();
					String pdfHtml = pdfInfo.replace("pdf", "html");
					String pdfs[] = pdfHtml.split("/");
					String filename[] = pdfs[1].split("\\.");
					System.out.println("报纸urlTTT");
					pdf2html("E:\\Pdf2HtmlEx\\pdf2htmlEX.exe --embed-css 0  --embed-javascript 0 --embed-image 0  --clean-tmp 1   --fit-width 1330 " + pdfInfo + "  --dest-dir " + pdfs[0]+"\\"+ filename[0] + "  " + pdfs[1] + "", "v.pdf", "v2.html");
				}
			}
		}
		return newsBeanData;
    }
}
